package com.smallA.association.config;


import com.smallA.association.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

@Data
@ConfigurationProperties("rsa.key")
//这里是绑定对应的配置文件的属性
public class RsaKeyProperties {

    private String pubKeyFile;
    private String priKeyFile;
    //这里就是通过配置文件来实现自动注入了

    private PublicKey publicKey;
    private PrivateKey privateKey;

    @PostConstruct
    public void createKey() throws Exception {
        publicKey = RsaUtils.getPublicKey(pubKeyFile.getBytes());
        privateKey = RsaUtils.getPrivateKey(priKeyFile.getBytes());
    }

}
